﻿using System.IO;

namespace Contacts.Web
{
   public partial class GetImage : BasePage
   {
      public const string _imagesDir = "C:\\Images\\";
      public const string _baseDir = "~\\Images\\";

      protected override void PageLoad()
      {
         if (!Directory.Exists(_imagesDir)) Directory.CreateDirectory(_imagesDir);

         string defaultFilename = Path.Combine(_imagesDir, "Default.png");
         if (!File.Exists(defaultFilename))
         {
            File.Copy(Server.MapPath(_baseDir) + "Default.png", defaultFilename);
         }

         string defaultIconFilename = Path.Combine(_imagesDir, "DefaultIcon.png");
         if (!File.Exists(defaultIconFilename))
         {
            File.Copy(Server.MapPath(_baseDir) + "DefaultIcon.png", defaultIconFilename);
         }

         Response.WriteFile(_imagesDir + Request.QueryString["file"]);
      }
   }
}